#ifndef SPIDER_FILTER_RULES_H_
#define SPIDER_FILTER_RULES_H_

#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <netinet/in.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/ip.h>
#include <netinet/udp.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <pthread.h>
#include <syslog.h>
#include <sys/time.h>
#include "utils.h"
#include "pps.h"
#include "ppsadapter.h"
#include "config.h"
#include "send_http_msg.h"
#include "pcre.h"

#include <arpa/inet.h>
#include <netdb.h>
#include <errno.h>
#include <stdlib.h>



#define safe_free(_x_) {if(_x_) {free(_x_); _x_=NULL;}}

#define TS_MAX_TITLE_VECTOR  (10*3)
#define TS_MAX_CHARSET_VECTOR  (10*3)

#define OVECCOUNT 30 /* should be a multiple of 3 */
#define TS_MAX_URL_VECTOR  (100*3)

//#define PATTERN_URLINFO  "(?im)GET (?<url>(:\\d+)?[-=\\/\\w\\.\\?&%#]*)"

//#define PATTERN_URLINFO    "(?im)GET\\s(?P<url>\\/[\\w\\.-]+(:\\d+)?[-=\\/\\w\\.\\?&%#]*)\\sHTTP\\/1\\.1"
#define PATTERN_URLINFO    "(?im)GET\\s(?P<url>.*)\\sHTTP\\/1\\.[01]\\r\\n(.*\\r\\n)*host:\\s(?P<host>.*)\\r\\n"


pcre *sfr_pcre_compile(char* pattern);
http_header_t *http_header_init();
void http_header_release(http_header_t *h);
int http_rule_pattern(http_header_t *h, spider_filter_rule_t *sfr, int rule_num);
char *http_search_urlinfo_in_buffer(pcre *re, char* buffer, const char **url, char **uriptr);
http_header_t * get_http_header(char *url_data);


#endif
